package servlet;

import dao.ImpI.SelectNumDaoImpI;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/thumpUp")
public class ThumpUp extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String value = req.getParameter("value");
        int v = Integer.parseInt(value);
        SelectNumDaoImpI selectNumDaoImpI = new SelectNumDaoImpI();
        boolean flag = selectNumDaoImpI.UpdateNum(++v);
        PrintWriter writer = resp.getWriter();
        if (flag){
            resp.setContentType("text/html;charset=utf-8");
            writer.print(v);
        }else {
            writer.print("更新失败");
        }
    }
}
